<?php
/**
 * Created by PhpStorm.
 * User: lenovo
 * Date: 2018/10/20
 * Time: 16:43
 */
header("content-type:text/html;charset=utf-8");
require COMMON_PATH.'logTool.class.php';
require COMMON_PATH.'message.class.php';
class OrderAction extends Action
{
    //处理订单
    public function order(){
        $back = message::fail('fail');
        //获取接收预约数据
        $name = isset($_REQUEST['name'])?$_REQUEST['name'].trim():'';
        $phone = isset($_REQUEST['phone'])?$_REQUEST['phone'].trim():'';
        $id_card = isset($_REQUEST['id_card'])?$_REQUEST['id_card'].trim():'';
        $address = isset($_REQUEST['address'])?$_REQUEST['address'].trim():'';
        $referrer = isset($_REQUEST['referrer'])?$_REQUEST['referrer'].trim():'';
        $order_date = time();
        $good_class = isset($_REQUEST['good_class'])?intval($_REQUEST['good_class']):'';
        $good_name = isset($_REQUEST['good_name'])?$_REQUEST['good_name']:'';
        $good_price = isset($_REQUEST['good_price'])?$_REQUEST['good_price']:'';
        $agree = isset($_REQUEST['agree'])?intval($_REQUEST['agree']):'';
        foreach ($_REQUEST as $item=>$value){
            logTool::logCat('遍历接收参数：'.$item.'------>'.$value);
        }
        if (empty($name)){
            $msg = '姓名不可为空';
            $back = message::fail($msg);
            logTool::logCat("存储订单消息返回信息：".$back);
            echo $back;
            return;
        }
        if (empty($phone)){
            $msg = '电话号码不可为空';
            $back = message::fail($msg);
            logTool::logCat("存储订单消息返回信息：".$back);
            echo $back;
            return;
        }
        if (empty($id_card)){
            $msg = '省份证号不可为空';
            $back = message::fail($msg);
            logTool::logCat("存储订单消息返回信息：".$back);
            echo $back;
            return;
        }
        if (empty($address)){
            $msg = '地址不可为空';
            $back = message::fail($msg);
            logTool::logCat("存储订单消息返回信息：".$back);
            echo $back;
            return;
        }
        if (empty($good_name) || empty($good_class) || empty($good_price)){
            $msg = '请选择一款套餐';
            $back = message::fail($msg);
            logTool::logCat("存储订单消息返回信息：".$back);
            echo $back;
            return;
        }
        if (empty($agree) || $agree == 0){
            $msg = "请阅读同意客户入网协议";
            $back = message::fail($msg);
            logTool::logCat("存储订单消息返回信息：".$back);
            echo $back;
            return;
        }
        //存入客户预约信息
        $order = M('order_list');
        $data = array(
            'name' => $name,
            'phone' => $phone,
            'id_card' => $id_card,
            'address' => $address,
            'referrer' => $referrer,
            'good_class' => $good_class,
            'good_name' => $good_name,
            'good_price' => $good_price,
            'order_date' => $order_date,
            'status' => 0,
            'agree' => 1,
            'is_delete' => 1
        );
        if ($order->add($data)){
            $back = message::success('success');
        }
        logTool::logCat("存储订单消息返回信息：".$back);
        echo $back;
        return;
    }
}